home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VGATUT1.ZIP / VGAPIXEL.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1995-08-02  |  4.9 KB  |  202 lines

  1. {$X+}
  2. {$G+}  {must have this to use 286 instruction set}
  3.  
  4. {Program by Richard Griffiths, written for VGA-TUT by Barnaby Mercer}
  5. {VGA-TUT Web page : http://zetnet.co.uk/users/bmercer/vgatut.htm}
  6.  
  7. {e-Mail: richard.griffiths@zetnet.co.uk}
  8. {      :      barny.mercer@zetnet.co.uk}
  9.  
  10. program pixel (input, output);
  11.  
  12. uses Crt;
  13.  
  14. const VGA_SEGMENT = $A000;    {We didn't need this but it helps make the code
  15.                                easier to read}
  16.  
  17. {------------------------------------------------------------------------}
  18.  
  19. procedure Set_Vid_mode_to_320x200;
  20.  
  21. Begin
  22.     asm
  23.        mov ax, 13h      {store 13h in AX}
  24.        int 10h          {call interrupt }
  25.     end;
  26. end;
  27.  
  28.  
  29. {------------------------------------------------------------------------}
  30.  
  31. procedure Return_Vid_Mode_To_Text;
  32.  
  33. begin
  34.    asm
  35.     mov ax, 03h      {store 03h in AX}
  36.     int 10h          {call interrupt }
  37.    end;
  38. end;
  39.  
  40. {------------------------------------------------------------------------}
  41.  
  42. procedure interupt (X,Y : Integer; Colour : Byte);
  43.  
  44.    { This puts a pixel on the screen using interrupts. }
  45.  
  46. begin
  47.   asm
  48.      mov        ah,0Ch
  49.      mov        al,[colour]
  50.      mov        cx,[x]
  51.      mov        dx,[y]
  52.      mov        bx,[1]
  53.      int        10h
  54.   end;
  55. end;
  56.  
  57. {------------------------------------------------------------------------}
  58.  
  59. procedure Direct_Memory_Access (X,Y : Integer; Colour : Byte; Offset 
  60. : Integer);
  61.  
  62. {This procedure places pixels using DMA, which is a lot faster}
  63.  
  64. begin
  65.  
  66.     Offset := (Y * 320) + X;      {as mentioned before, the Offset when using
  67.                                   the DMA method, must be calculated}
  68.     mem [VGA_SEGMENT:Offset] := Colour;
  69.    
  70. end;
  71.  
  72. {------------------------------------------------------------------------}
  73.  
  74. procedure assembler (X, Y : Integer; Colour : Byte);
  75.  
  76. begin
  77.     asm
  78.       mov ax, 0a000h   { point AX to video memory   }
  79.       mov es, ax       { move segment pointer to ES }
  80.                        { (actual pointer)           }
  81.       mov bx, [Y]
  82.       mov ax, bx       { register to register is faster by 1 clock}
  83.  
  84.       mov ah, al       { ax=y*256 + y}
  85.       mov al,  0       { ax=y*256    }
  86.  
  87.       shl bx, 6        { bx=y*64     }
  88.       add bx, ax       { bx=y*320    }
  89.  
  90.       add bx, [X]      { ax=(y*320)+x}
  91.       mov di, bx       { move video pointer to correct place}
  92.  
  93.       mov al, [Colour]
  94.       mov es:[di], al  { move colour to memory }
  95.    end;
  96. end;
  97.  
  98. {------------------------------------------------------------------------}
  99. procedure print_intro;
  100.  
  101. begin
  102.     ClrScr;
  103.     WriteLn ('This program aims to demonstrate 3 ways of writing 
  104. pixels to the screen.' );
  105.     WriteLn ;
  106.     WriteLn ('1. Interrupt pixels - This routine uses Int. 10h to 
  107. place a pixel (part ASM)' );
  108.     WriteLn ;
  109.     WriteLn ('2. DMA pixels       - These pixels are placed on screen 
  110. by writing directly');
  111.     WriteLn ('                      to memory.');
  112.     WriteLn ;
  113.     WriteLn ('3. ASM pixels       - This PutPixel routine was written 
  114. in assembler for speed.');
  115.     WriteLn ('');
  116.     WriteLn ('Each time the pixels will be painted on the screen from l-r.');
  117.     WriteLn ('Notice the differance in speed each time.');
  118.     WriteLn ('');
  119.     WriteLn ('Hit any key to continue..........');
  120.     ReadKey;
  121. end;
  122.  
  123. {------------------------------------------------------------------------}
  124.  
  125. procedure print_outro;
  126.  
  127. begin
  128.     ClrScr;
  129.     WriteLn ;
  130.     WriteLn ;
  131.     WriteLn ('Thats all for this issue..');
  132.     WriteLn ;
  133.     WriteLn ('Barny Mercer - 29/7/95 @ 12:39');
  134.     WriteLn ('barny.mercer@zetnet.co.uk  ');
  135.     WriteLn ;
  136.     WriteLn ('Ported to pascal by Richard Griffiths.');
  137.     WriteLn ('richard.griffiths@zetnet.co.uk');
  138.     WriteLn ;
  139.     WriteLn ('Thanks Richard - Barny');
  140.     ReadKey;
  141. end;
  142.  
  143.  
  144. {------------------------------------------------------------------------}
  145.  
  146. procedure print_interupt_pixel;
  147.  
  148. var counter_X, counter_Y : Integer;
  149.  
  150. begin
  151.   For counter_X:=0 to 319 do
  152.     For counter_Y:=0 to 199 do
  153.       interupt (counter_X, counter_Y, Random (256));
  154.   Readkey;
  155. end;
  156.  
  157. {------------------------------------------------------------------------}
  158.  
  159. procedure print_DMA_pixel;
  160.  
  161.  
  162. var counter_X, counter_Y : Integer;
  163.  
  164. begin
  165.   For counter_X:=0 to 319 do
  166.     For counter_Y:=0 to 199 do
  167.         Direct_Memory_Access (counter_X, counter_Y, Random (256));
  168.     ReadKey;
  169. end;
  170.  
  171.  
  172. {------------------------------------------------------------------------}
  173.  
  174. procedure print_ASM_pixel;
  175.  
  176. var pixel_X, pixel_Y : Integer;
  177.  
  178. begin
  179.   for pixel_x:=0 to 319 do
  180.     for pixel_Y:=0 to 199 do
  181.      assembler  (pixel_x, pixel_Y, Random (256));
  182.   Readkey;
  183. end;
  184.  
  185. {------------------------------------------------------------------------}
  186.  
  187. begin       {The main program}
  188.  
  189.      Print_intro;
  190.      Set_Vid_mode_to_320x200;
  191.      print_interupt_pixel;
  192.      print_DMA_pixel;
  193.      print_ASM_pixel;
  194.      Return_Vid_Mode_to_Text;
  195.      Print_outro;
  196.  
  197. end.
  198.  
  199.  
  200.  
  201.  
  202.